Removes AND returns the item at the top of target. If target is already empty, nothing is removed and a plain default value is returned instead (0/0.0/false/an empty string/`nothing`, depending on T) - target never crashes. Check stack_empty(target) first if you need to tell "the top was really this value" apart from "target was empty".
stack_pop(target) -> element| Name | Type |
|---|---|
target | stack |
element
Removes AND returns the item at the top of target. Everything under it becomes the new top.
If target is already empty, nothing is removed and a plain default value is returned instead (0/0.0/false/an empty string/nothing, depending on target's element type) - target never crashes. Check stack_empty(target) first if the game needs to tell "the top really was this value" apart from "target was empty."
/// @type {stack<int>}
var history = [1, 2, 3];
var top = stack_pop(history); // 3 - history is now [1, 2]
/// @type {stack<int>}
var empty_stack = [];
var fallback = stack_pop(empty_stack); // 0 - empty_stack was empty, so this is the default, not a real popped value



the GBA module's own vector back()+pop_back() - O(1), and the empty case is checked before either is called, so this can never read or pop past the end. The default-value fallback is a small compiled-in lambda - no allocation, no new engine primitive, same posture as every other operation on this page.